/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sasp_messages;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author mauriello
 */
public class NACKReply extends SASPReply {
    private String reason;
    
    public String getReason( ) {
        return reason;
    }
    
    public void setReason( String _r ) {
        reason = _r;
    }

    public NACKReply( ) {
        super( );
        this.setType(NACK);
    }

    public NACKReply( int _o, int _d, int _r, String _reason ) {
        super( _o, _d, _r );
        try {
            reason = _reason;
            this.setType(NACK);
            JSONObject body = new JSONObject();
            body.put("Reason", reason);
            this.setReplyBody(body);
        } catch (JSONException ex) {
            Logger.getLogger(NACKReply.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public NACKReply( String _s ) {
        super( _s );
        try {
            reason = this.getReplyBody().getString("Reason");
            saspmanager.SASPManagerApp.addLine("RPL - Ack Reply Received");
        } catch (JSONException ex) {
            Logger.getLogger(NACKReply.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 

    @Override
    public void updateReplyBody() {
        try {
            JSONObject body = new JSONObject();
            body.put("Reason", reason);
            this.setReplyBody(body);
        } catch (JSONException ex) {
            Logger.getLogger(NACKReply.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
